﻿
using Microsoft.Practices.Unity;

namespace MvvmFx.Common.ViewModels.Behaviors.ProcessManagement
{
    /// <summary>
    /// Abstract base class for loading profile state objects with the
    /// data from the object being profiled and the current simulation context.
    /// </summary>
    public abstract class StateLoader<T> : IStateLoader<T> where T : ProcessState
    {
        #region Constructor

        protected StateLoader(IUnityContainer container)
        {
            this.Container = container;
        }

        #endregion

        #region properties

        /// <summary>
        /// Dependency container to be used for DI by child classes.
        /// </summary>
        protected IUnityContainer Container
        {
            get;
            private set;
        }

        #endregion

        #region Public methods

        /// <summary>
        /// Load the profile page object, using the data in the manager's State
        /// </summary>
        /// <returns></returns>
        public void Load(T state)
        {
            OnLoad(state);

            // Mark the state as being UnModified
            state.IsModified = false;
        }

        #endregion

        #region Protected methods

        /// <summary
        /// Implement in derived classes to load the state from the object
        /// </summary>
        /// <returns></returns>
        protected abstract void OnLoad(T state);

        #endregion

        #region IStateLoader Members

        void IStateLoader.Load(ProcessState state)
        {
            Load((T)state);
        }

        #endregion
    }
}